home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DAboutBox.cpp next >
Text File  |  1996-07-05  |  4KB  |  178 lines

  1. // DAboutBox.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "DAboutBox.h"
  6. #include "DApplication.h"
  7. #include "DWindow.h"
  8. #include "DTask.h"
  9.  
  10.  
  11. Local char *dclapinfo =
  12. "using Don's C++ Class Application Library (DCLAP)"LINEEND
  13. "D.Gilbert, Indiana Univ. Biology Dept."LINEEND
  14. "software@bio.indiana.edu";
  15.  
  16. Local char *ncbiinfo =
  17. "and the VIBRANT cross-platform toolkit from"LINEEND
  18. "National Center for Biotechnology Information"LINEEND
  19. "National Library of Medicine, N.I.H."LINEEND
  20. "info@ncbi.nlm.nih.gov";
  21.  
  22. Local char *shortinfo =
  23. "using Don's Class App Library (DCLAP), software@bio.indiana.edu"LINEEND
  24. "and VIBRANT cross-platform toolkit, info@ncbi.nlm.nih.gov";
  25.  
  26.  
  27. //class DAboutBoxPanel : public DPanel 
  28.  
  29. DAboutBoxPanel::DAboutBoxPanel(DWindow* itsWindow, const char* aboutText) :
  30.     DPanel( 0, itsWindow, 25 * Nlm_stdCharWidth, 12 * Nlm_stdLineHeight, simple),
  31.     fKeepItShort(false),
  32.     fAboutLines(0),
  33.     fDclapLines(0),
  34.     fNcbiLines(0),
  35.     fAboutText(NULL)
  36. {
  37.     if (aboutText)
  38.         fAboutText= StrDup(aboutText);
  39.     else {
  40.         char *name = (char*)gApplication->Shortname();
  41.         if ( name ) {
  42.             fAboutText= StrDup( name);
  43.             if (DApplication::kVersion) StrExtendCat( &fAboutText, DApplication::kVersion);
  44.             StrExtendCat( &fAboutText, ", an app written");
  45.             }
  46.         else
  47.             fAboutText= StrDup("An application written");
  48.         }
  49.      SizeInfo();
  50. }
  51.  
  52. DAboutBoxPanel::~DAboutBoxPanel() 
  53. {
  54.     MemFree(fAboutText);
  55. }
  56.         
  57. void DAboutBoxPanel::Release(Nlm_PoinT mouse) 
  58. {
  59.     DWindow* mywind= this->GetWindow();
  60.     if (mywind) mywind->Close();
  61. }
  62.  
  63.  
  64. void DAboutBoxPanel::SizeOneText(const char* text, long& maxlen, short& linecount)
  65. {
  66.     char *cp, *cp0;
  67.     long    len;
  68.     for (linecount= 0, cp= (char*)text; cp && *cp; ) {
  69.         cp0= cp;
  70.         cp= StrChr( cp, NEWLINE);  
  71.         linecount++;
  72.         if (!cp) len= StrLen(cp0);
  73.         else { len= cp-cp0; cp++; }
  74.         if (len>maxlen) maxlen= len;
  75.         }
  76. }
  77.  
  78. void DAboutBoxPanel::SizeInfo()
  79. {
  80.     long     maxlen = 0;
  81.  
  82.     SizeOneText( fAboutText, maxlen, fAboutLines);
  83.     fKeepItShort = (fAboutLines > 20);
  84.  
  85.     if (fKeepItShort) {
  86.         SizeOneText( shortinfo, maxlen, fDclapLines);
  87.         }
  88.     else {
  89.         SizeOneText( dclapinfo, maxlen, fDclapLines);
  90.         SizeOneText( ncbiinfo, maxlen, fNcbiLines);
  91.         }
  92.  
  93. #if THIS_ISNT_WORKING_TO_RESIZE_WINDOW
  94.     maxlen= Min(80, maxlen); // fix for actual screen size...
  95.     //this->ViewRect(r);
  96.     this->GetPosition(r);
  97.     //Nlm_GetRect( (Nlm_GraphiC)fPanel, &r);
  98.     r.right = r.left + Nlm_stdCharWidth * maxlen;
  99.     r.bottom= r.top + 12 + Nlm_stdLineHeight * (fAboutLines + fDclapLines + fNcbiLines);
  100.     //Nlm_SetRect( (Nlm_GraphiC)fPanel, &r);
  101.     this->SetPosition(r);
  102. #endif
  103. }
  104.  
  105.  
  106.  
  107. void DAboutBoxPanel::Draw()
  108. {
  109.     Nlm_RecT  r;
  110.     short    lineheight;
  111.     this->ViewRect(r);
  112.     Nlm_InsetRect (&r, 2, 2);
  113.     Nlm_SelectFont(Nlm_systemFont);
  114.     lineheight=  Nlm_LineHeight();
  115.  
  116.     r.top += 6;
  117.     r.bottom = r.top + 1 + fAboutLines * lineheight;
  118.     Dgg_DrawTextbox( &r, fAboutText, StrLen(fAboutText), 'c', false);
  119.  
  120.     if (fKeepItShort) {
  121.         r.top = r.bottom + 6;
  122.         Nlm_Blue();
  123.         r.bottom = r.top + 1 + fDclapLines * lineheight;
  124.         Dgg_DrawTextbox( &r, shortinfo, StrLen(shortinfo), 'c', false);
  125.         }
  126.  
  127.     else {
  128.         r.top = r.bottom + 6;
  129.         Nlm_Blue();
  130.         r.bottom = r.top + 1 + fDclapLines * lineheight;
  131.         Dgg_DrawTextbox( &r, dclapinfo, StrLen(dclapinfo), 'c', false);
  132.  
  133.         r.top = r.bottom + 6;
  134.         Nlm_Red();
  135.         r.bottom = r.top + 1 + fNcbiLines * lineheight;
  136.         Dgg_DrawTextbox( &r, ncbiinfo, StrLen(ncbiinfo), 'c', false);
  137.         }
  138. }
  139.  
  140.  
  141.  
  142. //class DAboutBoxWindow : public DWindow
  143.  
  144.  
  145.  
  146. DAboutBoxWindow::DAboutBoxWindow(const char* aboutText) :
  147.     DWindow( 0, gApplication, fixed)
  148. {
  149.     fModal = false;
  150.     fMypanel = new DAboutBoxPanel(this, aboutText);  // create my panel
  151.     if (PoseModally()) ;
  152. }
  153.  
  154.  
  155. DAboutBoxWindow::~DAboutBoxWindow()
  156. {
  157.     //delete fMypanel; /// nooooo.... dview::deletesubviews
  158. }
  159.         
  160. void DAboutBoxWindow::Close() 
  161. #if 0
  162.     if (fModal) {
  163.         fModal= false;
  164.         DTask* closetask= new DTask(DApplication::kClose, DTask::kMenu,
  165.                         gApplication);
  166.         this->PostTask(closetask);
  167.         }
  168.     else
  169. #endif
  170.     DWindow::Close();
  171.     //delete this; // mswin gets sick here if win == modal kind
  172. }
  173.  
  174.  
  175.  
  176.  
  177.